package com.mt.course.service.model;

import java.util.List;
import java.util.Map;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.github.pagehelper.PageHelper;
import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.course.entity.ServiceConfigEntity;
import com.mt.course.mapper.ServiceConfigEntityMapper;

@Component
public class ServiceConfigServiceModel {
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ServiceConfigServiceModel.class);

    @Autowired
    private ServiceConfigEntityMapper serviceConfigEntityMapper;

    public ServiceResult<List<ServiceConfigEntity>> selectList(Map<String, Object> params, PagerInfo<?> pagerInfo) {
        Assert.notNull(this.serviceConfigEntityMapper, "Property 'serviceConfigEntityMapper' is required.");
        ServiceResult<List<ServiceConfigEntity>> result = new ServiceResult<List<ServiceConfigEntity>>();
        try {
            if (pagerInfo != null) {
                PageHelper.startPage(pagerInfo.getPageIndex(), pagerInfo.getPageSize());
            }
            result.setResult(this.serviceConfigEntityMapper.selectList(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ServiceConfigServiceModel][selectList]：query findList occur exception", e);
        }
        return result;
    }

    public ServiceResult<ServiceConfigEntity> selectInfo(Map<String, Object> params) {
        Assert.notNull(this.serviceConfigEntityMapper, "Property 'serviceConfigEntityMapper' is required.");
        ServiceResult<ServiceConfigEntity> result = new ServiceResult<ServiceConfigEntity>();
        try {
            result.setResult(this.serviceConfigEntityMapper.selectByPrimaryKey(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ServiceConfigServiceModel][selectInfo]：query selectInfo occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> insert(ServiceConfigEntity ServiceConfigEntity) {
        Assert.notNull(this.serviceConfigEntityMapper, "Property 'serviceConfigEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.serviceConfigEntityMapper.insert(ServiceConfigEntity);
            if (save > 0) {
                id = ServiceConfigEntity.getServiceConfigId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ServiceConfigServiceModel][insert]：query insert occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateByPrimaryKeySelective(ServiceConfigEntity ServiceConfigEntity) {
        Assert.notNull(this.serviceConfigEntityMapper, "Property 'serviceConfigEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int save = 0;
        try {
            save = this.serviceConfigEntityMapper.updateByPrimaryKeySelective(ServiceConfigEntity);
            result.setResult(save);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ServiceConfigServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> deleteByPrimaryKey(Integer systemConfigId) {
        Assert.notNull(this.serviceConfigEntityMapper, "Property 'serviceConfigEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            int save = this.serviceConfigEntityMapper.deleteByPrimaryKey(systemConfigId);
            result.setResult(save);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ServiceConfigServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }
}
